#include <cstdio>

int main( )
{
    int f[ 401 ], i, n, t, a, b, time;
    scanf("%d", &t);
    while ( t-- )
    {
        for ( i = 1; i <= 400; i++ )
            f[ i ] = 0;
        scanf("%d", &n);
        while ( n-- )
        {
            scanf("%d%d", &a, &b);
            a += a & 1;
            b += b & 1;
            if ( a > b )
            {
                i = a;
                a = b;
                b = i;
            }
            for ( i = a; i <= b; i++ )
                f[ i ]++;
        }
        time = 0;
        for ( i = 1; i <= 400; i++ )
            if ( time < f[ i ] )
                time = f[ i ];
        printf("%d\n", time * 10);
    }
    return 0;
}
